import 'package:sow_app_core/sow_app_core.dart';
import '../usecase/usecase.dart';

abstract class FeedbackController {
  final FeedbackPresenter _presenter;
  final UserRepository _userRepository;

  FeedbackController(this._presenter, this._userRepository);
  init() => FeedbackInitUseCase(_presenter, _userRepository)(NoParams());

  void addFeedBack(String value) =>
      AddFeedbackUseCase(_presenter, _userRepository)(value);
}

class FeedbackInitUseCase extends UseCase<Future<void>, NoParams> {
  final FeedbackPresenter _presenter;
  final UserRepository _userRepository;

  FeedbackInitUseCase(this._presenter, this._userRepository);
  @override
  Future<void> call(NoParams params) async {
    _presenter.feedbackList =
        await GetFeedbackListUseCase(_userRepository)(NoParams());
    _presenter.onComplete();
  }
}

class GetFeedbackListUseCase extends UseCase<Future<List<Feedback>>, NoParams> {
  final UserRepository _userRepository;

  GetFeedbackListUseCase(this._userRepository);
  @override
  Future<List<Feedback>> call(NoParams params) =>
      _userRepository.getFeedbackList();
}

class AddFeedbackUseCase extends UseCase<void, String> {
  final FeedbackPresenter _presenter;
  final UserRepository _userRepository;

  AddFeedbackUseCase(this._presenter, this._userRepository);
  @override
  void call(String params) async {
    await _userRepository.addFeedback(params);
    _presenter.feedbackList =
        await GetFeedbackListUseCase(_userRepository)(NoParams());
    _presenter.onComplete();
  }
}
